<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class PayBillModel extends BaseModel
{
    use HasFactory;

    protected $table = 't_pay_bill';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    //开票状态 1未开票 2已开票
    const TICKET_NOT_ISSUED = 1;
    const TICKET_ISSUED = 2;
    const TICKET_STATUS_MAPS = [
        self::TICKET_NOT_ISSUED => '未开票',
        self::TICKET_ISSUED => '已开票',
    ];


    //状态 1待提交 2待审核 3待付款 4已付款
    const STATUS_WAIT_SUBMIT = 1;
    const STATUS_WAIT_AUDIT = 2;
    const STATUS_WAIT_PAY = 3;
    const STATUS_PAID = 4;
    const STATUS_MAPS = [
        self::STATUS_WAIT_SUBMIT => '待提交',
        self::STATUS_WAIT_AUDIT => '待审核',
        self::STATUS_WAIT_PAY => '待付款',
        self::STATUS_PAID => '已付款',
    ];


    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //客户
    public function agent(): BelongsTo {
        return $this->belongsTo(AgentModel::class, 'agent_id');
    }

    //开票/收款
    public function ticket(): HasMany {
        return $this->hasMany(PayBillTicketModel::class, 'pay_bill_id');
    }

    public function take_order_ids(): HasMany {
        return $this->hasMany(PayBillIdsModel::class, 'pay_bill_id');
    }

}
